﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.Xna.Framework.Graphics;   //   for Texture2D
using Microsoft.Xna.Framework;  //  for Vector2

namespace zombieArena
{
    class Enemy : Character
    {
        // optimize
        Vector2 drawOrigin;
        Rectangle sourceRect;
        public int points;
        public float collisionRadius;

        /// <summary>
        /// 1: standard zombie
        /// 2: large zombie
        /// 3: fast zombie
        /// </summary>
        public int type;
        public float speed;

        public Enemy(int initX, int initY, int height, int width, Texture2D playerTexture, int type)
        {
            // Initializing player
            this.position = new Vector2(initX, initY);
            this.velocity = new Vector2(15, 15);
            this.charTexture = playerTexture;
            this.height = height;
            this.width = width;
            this.directionAngle = 0;
            this.lookAngle = 0;
            currentSprite = 0;
            spriteRow = 2;
            this.state = "ALIVE";
            this.points = 10;
            this.type = type;
            collisionRadius = 40;

            switch(type)
            {
                case 1:
                    lives = 1;
                    speed = 2;
                    break;
                case 2:
                    lives = 3;
                    speed = 1.5f;
                    collisionRadius = 60;
                    break;
                case 3:
                    lives = 1;
                    speed = 4;
                    break;
                default:
                    lives = 1;
                    speed = 2;
                    break;
            }

            hitColor = Color.White;

            // optimize: avoid constant new Vector2, new Rectangle
            drawOrigin = new Vector2(width / 2, height / 2);
            sourceRect = new Rectangle(56 * currentSprite, 80 * spriteRow, width, height);
        }

        public void draw(ref Vector2 enemyscreenpos, ref SpriteBatch spriteBatch)
        {
            // optimize: avoid constant new Rectangle
            sourceRect.X = 56  * currentSprite;
            sourceRect.Y = 80 * spriteRow;

            switch (type)
            {
                case 2:
                    spriteBatch.Draw(charTexture, enemyscreenpos, sourceRect, hitColor, 0f, drawOrigin, 1.5f, SpriteEffects.None, 0f);
                    break;
                default:
                    spriteBatch.Draw(charTexture, enemyscreenpos, sourceRect, hitColor, 0f, drawOrigin, 1f, SpriteEffects.None, 0f);
                    break;
            }
        }

        public Color hitColor;
        byte colorInterval = 16;
        int currentColor = 255;
        public void updateColor()
        {
            if (currentColor < 255)
            {
                hitColor.B = (byte)currentColor;
                hitColor.G = (byte)currentColor;
                currentColor += colorInterval;
            }
            if (currentColor >= 255)
            {
                currentColor = 255;
                hitColor.B = (byte)currentColor;
                hitColor.G = (byte)currentColor;
            }
            
            
        }

        public void changeHitColor()
        {
            hitColor.B = 0;
            hitColor.G = 0;
            currentColor = 0;
        }

        // colored enemies (laser pointer)
        public void draw(Vector2 enemyscreenpos, SpriteBatch spriteBatch, Color color)
        {
            // optimize: avoid constant new Rectangle
            sourceRect.X = 56 * currentSprite;
            sourceRect.Y = 80 * spriteRow;

            spriteBatch.Draw(charTexture, enemyscreenpos, sourceRect, color, 0f, drawOrigin, 1f, SpriteEffects.None, 0f);
        }
    }
}
